
// pages/community/community.js
Page({
  data: {
    active: 1,
    posts: [] // 帖子列表
  },

  // community.js

  onShow() {
    this.loadLocalPosts();
  },

  // 加载本地帖子
  loadLocalPosts() {
    const posts = wx.getStorageSync('posts') || [];
    this.setData({ posts });
  },

  // 点赞功能（本地版）
  onLike(e) {
    const postId = e.currentTarget.dataset.id;
    const posts = this.data.posts.map(post => {
      if (post.id === postId) {
        return {
          ...post,
          likes: post.likes + 1,
          isLiked: true
        };
      }
      return post;
    });
    
    this.setData({ posts });
    wx.setStorageSync('posts', posts);
  }

});


